# -*- coding: utf-8 -*-
"""
Created on Fri Oct  5 12:55:01 2012

@author: nico


Debugging and test file for import filters
"""

from importfilters import *
from numpy import *
import matplotlib.pyplot as plt
from pylab import *  
from scipy import stats 

nbcol=3
samplerate=5e5

#inputfile='/Users/nicolas/Documents/Manips/80T benoit/Kish-1p5K-14'
inputfile='/Users/nicolas/Documents/Manips/YBCO6p59c2-box10-juin11/YBCO6p59c2_94K-01'
temp=loadfileFFC(inputfile,10E6,nbcol)

#Affiche un aperçu
#plot(temp[arange(1,len(temp),100)])

figure()
#Affiche le dbdt
dbdt=temp[:,0]
temps=arange(0,len(dbdt))*1/samplerate
#plot(temps,dbdt)

#calcul simple de l'offset basé sur la moyenne globale
#plot(field_integration(dbdt,1E7,'all'))
#
##calcul simple de l'offset basé sur la moyenne des 100 premier points
#plot(field_integration(dbdt,1E7,'start'))
#
##calcul simple de l'offsetbasé sur la moyenne des 100 derniers points
#plot(field_integration(dbdt,1E7,'end'))
#
#dbdt=-dbdt[arange(len(dbdt)-1,0,-1)]

champ=field_integration(dbdt,samplerate,'end')/0.0005032

#plot(champ)

champ_corr=field_adjust(champ)
    
plot(champ_corr)    
temps=arange(0,len(champ))*1/samplerate
#temps=arange(0,size(champ_corr)/samplerate,1/samplerate)
freq = fftfreq(champ_corr.size,1/samplerate)

sp=fft(champ_corr-mean(champ_corr),pow(2,24))
freq = fftfreq(sp.size,1/samplerate)
#plot(freq, sp.real, freq, sp.imag)
figure()
plot(freq[:1000], log(abs(sp[:1000])))